package com.lanmei.group.weixin.interceptor;


import javax.servlet.http.HttpSession;

import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;
import com.jfinal.core.Controller;
import com.lanmei.group.weixin.common.Constant;
import com.lanmei.group.weixin.model.ManagerInfo;
import com.lanmei.group.weixin.utils.RequestUtil;
import com.lanmei.group.weixin.utils.ShiroUtil;

public class ManagerInterceptor implements Interceptor {

	@Override
	public void intercept(Invocation inv) {
		Controller controller = inv.getController();
		HttpSession session = controller.getSession();
		Integer siteId = RequestUtil.getSiteId(session);
		String loginName = ShiroUtil.getLoginName();
		ManagerInfo manager = new ManagerInfo().findManagerInfoByLoginName(loginName);
		if(manager.getSiteId()!=siteId){
			controller.redirect("/admin/index");
			return;
		}
		inv.invoke();
	}
}
